# !/usr/bin/python
# -*- coding: utf-8 -*-
'''
@File    :   14_quicksort.py
@Time    :   2021/04/01 21:51:58
@Author  :   Qingxiang Zhang
@Version :   1.0
@Contact :   344285081@qq.com
@Desc    :   快速排序算法

@Software:    Vscode
'''
'''
快速排序：利用两个游标，靠着游标的移动，一直交换数值
'''

def quick_sort(aList,start,end):
    if start >= end:
        return aList
    mid_value = aList[start]
    low = start
    hight = end
    while low < hight:
        while low < hight and aList[hight] >= mid_value:
            hight -= 1
        aList[low] = aList[hight]
        while low < hight and aList[low] < mid_value:
            low += 1
        aList[hight] = aList[low]
    aList[low] = mid_value
    # 使用递归策略对函数进行递归，两边分开计算
    quick_sort(aList,start,low-1)
    quick_sort(aList,low+1,end)

if __name__=="__main__":
    aList=[1,34,6,76,5]
    quick_sort(aList,0,len(aList)-1)
    print(aList)
 
 

   

 